import request from '@/utils/request'

/**
 * 帐号登录
 * @param {String} account - 用户名
 * @param {String} password - 密码
 * @returns Promise
 */
export const userAccountLoginAPI = ({ account, password }) =>
  request('/login', { account, password }, 'post')

/**
 * 短信登录
 * @param {String} mobile - 手机号
 * @param {String} code - 验证码
 * @returns Promise
 */
export const userMobileLoginAPI = ({ mobile, code }) =>
  request('/login/code', { mobile, code }, 'post')

/**
 * 获取短信登录验证码
 * @param {String} mobile - 手机号
 * @returns Promise
 */
export const userMobileLoginMsgAPI = mobile =>
  request('/login/code', { mobile })

/**
 * QQ登录
 * @param {String} unionId - QQ唯一标识，openId
 * @param {*} source - 客户端类型 1 PC
 * @returns
 */
export const userQQLoginAPI = (unionId, source = 1) =>
  request('/login/social', { unionId, source }, 'post')

/**
 * 获取QQ绑定的时候短信验证码
 * @param {String} mobile - 手机号
 * @returns promise
 */
export const userQQBindCodeAPI = mobile =>
  request('/login/social/code', { mobile })

/**
 * QQ登录-绑定帐号
 * @param {String} unionId - QQ唯一标识，openId
 * @param {String} mobile - 手机号
 * @param {String} code - 验证码
 * @returns
 */
export const userQQBindLoginAPI = ({ unionId, mobile, code }) =>
  request('/login/social/bind', { unionId, mobile, code }, 'post')

/**
 * 校验用户是否存在
 * @param {String} account - 帐号
 * @returns promise
 */
export const userAccountCheckAPI = account =>
  request('/register/check', { account })

/**
 * 获取QQ完善信息的时候短信验证码
 * @param {String} mobile - 手机号
 * @returns promise
 */
export const userQQPatchCodeAPI = mobile =>
  request('/register/code', { mobile })

/**
 * QQ登录-完善信息
 * @param {String} unionId - QQ唯一标识，openId
 * @param {String} mobile - 手机号
 * @param {String} code - 验证码
 * @param {String} account - 帐号
 * @param {String} password - 密码
 * @returns
 */
export const userQQPatchLoginAPI = ({
  unionId,
  mobile,
  code,
  account,
  password
}) =>
  request(
    `/login/social/${unionId}/complement`,
    { unionId, mobile, code, account, password },
    'post'
  )
